package com.axjy.web;

import com.axjy.dto.InspectiontaskMainDto;
import com.axjy.pojo.*;
import com.axjy.service.InspectiontaskMainService;
import com.axjy.service.vo.Pager;
import com.axjy.util.Log;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 00 on 2018/2/25.
 */
@RestController
@RequestMapping("/zdfp")
public class InspectiontaskMainHandler {

    @Resource
    private InspectiontaskMainService mainService;


    @GetMapping("/search1")
    public List<Systemconfig> search1(){return mainService.search1();}

    @GetMapping("/search2")
    public List<LineInfo> search2(){return mainService.search2();}

    @GetMapping("/search3")
    public List<User> search3(){return mainService.search3();}



    @GetMapping("/rwzdfp")
    public Pager xjzdfp(@RequestParam(required = false,defaultValue = "0") Integer offset, @RequestParam(required = false,defaultValue = "4") Integer limit, @Param("dto")InspectiontaskMainDto dto){
        Pager pager=mainService.xjzdfp(offset, limit, dto);
        return pager;
    }

    @PostMapping("/fzrupdate")
    public String fzrupdate(InspectiontaskMain inspectiontaskMain){
        String isOk=null;
        try{
            mainService.fzrupdate(inspectiontaskMain);
            isOk="新增成功";
        }catch (Exception ex){
            isOk="新增失败";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }


    @PostMapping("/add")
    public String add(InspectiontaskMain inspectiontaskMain,Integer id){
        String isOk=null;
        System.out.println(inspectiontaskMain.getTaskStatus());
        try{
            mainService.add(inspectiontaskMain,id);
//            mainService.rwUpdate(id);
            isOk="新增成功";
        }catch (Exception ex){
            isOk="新增失败";
            System.out.println();
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }
    @PostMapping("/update")
    public String update(InspectiontaskMain inspectiontaskMain){
        String isOk=null;
        try{
            mainService.update(inspectiontaskMain);
            isOk="修改成功";
        }catch (Exception ex){
            isOk="修改失败";
            System.out.println();
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }




    @PostMapping("/fpUpdate")
    public String fpUpdate(InspectiontaskMain inspectiontaskMain){
        String isOk=null;
        try{
            inspectiontaskMain.setTaskStatus(2);
            inspectiontaskMain.setTaskStatusName("已分配");
            mainService.fpUpdate(inspectiontaskMain,inspectiontaskMain.getUserId());
            isOk="修改成功";
        }catch (Exception ex){
            isOk="修改失败";
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }

//    @PostMapping("/delete")
//    public String delete(String[] ids){
//        String isOk=null;
//            Map<String,Object> map=new HashMap<>();
//            map.put("ids",ids);
//            isOk="删除成功";
//        try{
//            mainService.delete(map);
//        }catch (Exception ex){
//            isOk="删除失败";
//            System.out.println();
//            Log.logger.error(isOk,ex);
//        }
//        return isOk;
//    }

    @PostMapping("/delete")
    public String delete(Integer isCancel,Integer id){
        String isOk=null;
        isOk="取消成功";
        try{
            mainService.delete(isCancel, id);
        }catch (Exception ex){
            isOk="取消失败";
            System.out.println();
            Log.logger.error(isOk,ex);
        }
        return isOk;
    }


}
